<?php
$db_cat = new db_query('SELECT * FROM categories_multi WHERE lang_id=' . $lang_id . ' AND cat_type="product" AND cat_has_child=0 AND cat_active=1 ORDER BY cat_order ASC,cat_name ASC');
while ($cat = mysql_fetch_array($db_cat->result))
{
$db_listing	= new db_query("SELECT *
				FROM products_multi INNER JOIN product_hits ON pro_id = ph_id
				WHERE pro_category_id=" . $cat['cat_id'] ."
				ORDER BY ph_hits DESC LIMIT 6");
if (mysql_num_rows($db_listing->result) > 0)
{
?>
<div class="module_larger_title">
	<div class="L"></div>
	<div class="C"><a href="" lang="<?php echo $array_lang[$lang_id][0];?>"><?php echo $cat['cat_name'];?></a></div>
	<div class="R"></div>
</div>
<div class="module_larger padding_home">
	<table class="product_table_thumbnail_home" cellpadding="0" cellspacing="0">
	<tbody>
	<?php
	$i = 0;
	while (($listing = mysql_fetch_array($db_listing->result)) || ($i % 3 != 0))
	{
		if ($i % 3 == 0)
		{
			echo '<tr>';
		}
		if ($listing)
		{
			$db_pp = new db_query('SELECT * FROM product_pictures WHERE pp_product_id=' . $listing['pro_id'] . '');
			$pp = mysql_fetch_array($db_pp->result);
			unset($db_pp);
			//Load library extensiton in php.ini
			if(!extension_loaded("gd")){
				if(strtoupper(substr(PHP_OS, 0, 3) == "WIN")) dl("php_gd2.dll");
				else dl("gd2.so");
			}
                        //var_dump(file_exists('products_pictures/' . $listing['pro_picture']));
			//Get new dimensions
			if ($listing['pro_picture'] != '' && file_exists('products_pictures/' . $listing['pro_picture']))
			{
				list($width, $height) = getimagesize('products_pictures/' . $listing['pro_picture']);
			}
		}
	?>
	<td width="33%">
		<?php
		if ($listing)
		{
		?>
		<div class="product_picture">
			<center>
				<span>
					<a class="product_picture_thumbnail" title="<?php echo $listing['pro_name'];?>" href="<?php echo generate_detail_url('product',$listing['pro_category_id'],$listing['pro_id'],$listing['pro_name']);?>" rel="<img src='/products_pictures/<?php echo $pp['pp_picture'];?>' width='<?php echo $width;?>' height='<?php echo $height;?>' />" style="background-image:url(/products_pictures/small_<?=$listing['pro_picture'];?>)"></a>
				</span>
			</center>
		</div>
		<div class="product_name"><a href="<?php echo generate_detail_url('product',$listing['pro_category_id'],$listing['pro_id'],$listing['pro_name']);?>"><?php echo $listing['pro_name'];?></a></div>
		<div class="product_price"><font lang="<?php echo $array_lang[$lang_id][0];?>"><?php echo $lang_display['Gia_ban'];?></font>: <span class="price"><?php echo format_number($listing['pro_price']);?> <?php echo $lang_display['VND'];?></span></div>
		<div class="add_to_cart"><center><a title="<?php echo $lang_display['Xem_chi_tiet'];?>" href="<?php echo generate_detail_url('product',$listing['pro_category_id'],$listing['pro_id'],$listing['pro_name']);?>" lang="<?php echo $array_lang[$lang_id][0];?>"><?php echo $lang_display['Xem_chi_tiet'];?></a></center></div>
		<?php
		}
		?>
	</td>
	<?php
		if ($i % 3 == 2)
		{
			echo '</tr>';
		}
		++$i;
	}
	unset($db_listing);
	?>
	</tbody>
	</table>
</div>
<div class="module_bottom"><div class="fl"></div><div class="fr"></div></div>
<?php
}
}
unset($db_cat);
?>